# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=partio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.1
pkgrel=2
pkgdesc="A library for particle IO and manipulation (mingw-w64)"
arch=('any')
url="https://github.com/wdas/partio/"
license=("custom")
depends=("${MINGW_PACKAGE_PREFIX}-freeglut"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-swig")
optdepends=("${MINGW_PACKAGE_PREFIX}-python3: Python module for partio")
options=('staticlibs' '!emptydirs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/wdas/partio/archive/v${pkgver}.tar.gz
        001-install-layout.patch)
sha256sums=('49f0d61bcca4ac3900dc68fdf11fa325cec6fab6cedde37c5a2ce365b1b46112'
            '02bbebb3dc97501eb2634759915304511e2ffef60882f23103c9644d6f69b940')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-install-layout.patch
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    ../${_realname}-${pkgver}

  make #VERBOSE=1
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}

  make DESTDIR=${pkgdir} install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
